//
//  HEAITipsCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/23.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEAITipsCell.h"

@interface HEAITipsCell ()

@property (nonatomic, strong) UILabel *iconQLb;
@property (nonatomic, strong) UILabel *iconALb;

@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UILabel *contentLb;

@end

@implementation HEAITipsCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initUI];
    }
    return self;
}

- (void)initUI {
 
    _iconQLb = [UILabel new];
    _iconQLb.text = @"Q";
    _iconQLb.font = DYBlodFont(15);
    _iconQLb.textColor = KWhiteColor;
    _iconQLb.backgroundColor = KHexColor(@"1396DB");
    _iconQLb.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview: _iconQLb];
    
    _titleLb = [UILabel new];
    _titleLb.text = @"-";
    _titleLb.font = DYBlodFont(15);
    _titleLb.textColor = CNavBgColor;
    _titleLb.numberOfLines = 0;
    [self.contentView addSubview: _titleLb];
    
    _iconALb = [UILabel new];
    _iconALb.text = @"A";
    _iconALb.font = DYBlodFont(15);
    _iconALb.textColor = KWhiteColor;
    _iconALb.backgroundColor = CNavSubTitleColor;
    _iconALb.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview: _iconALb];
    
    _contentLb = [UILabel new];
    _contentLb.text = @"-";
    _contentLb.font = DYFont(15);
    _contentLb.textColor = CNavLightBlackColor;
    _contentLb.numberOfLines = 0;
    [self.contentView addSubview: _contentLb];
    
//    _titleLb.preferredMaxLayoutWidth = 100;
    
    CGFloat qw = [@"Q" widthForFont:DYBlodFont(15)] + 10;
    
    [_iconQLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.left.equalTo(self.contentView).mas_offset(0);
        make.width.height.mas_offset(qw);
    }];
    _iconQLb.layer.masksToBounds = YES;
    _iconQLb.layer.cornerRadius = qw/2.0;
    _iconALb.layer.masksToBounds = YES;
    _iconALb.layer.cornerRadius = qw/2.0;
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.left.equalTo(_iconQLb.mas_right).mas_offset(5);
        make.right.equalTo(self.contentView).mas_offset(5);
    }];
    
    [_iconALb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(10);
        make.left.equalTo(self.contentView).mas_offset(0);
        make.width.height.mas_offset(qw);
    }];

    [_contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(10);
        make.left.equalTo(_iconALb.mas_right).mas_offset(5);
        make.right.equalTo(self.contentView).mas_offset(5);
        make.bottom.equalTo(self.contentView).mas_offset(-5);
    }];
}

- (void)setModel:(NSDictionary *)model {
    _model = model;
    
    _titleLb.text = model[@"name"];
    _contentLb.text = [DYTools isBlankString:model[@"value"]] ? @"-" : model[@"value"];
}

- (UICollectionViewLayoutAttributes*)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes*)layoutAttributes {
    [self setNeedsLayout];
    [self layoutIfNeeded];
    CGSize size = [self.contentView systemLayoutSizeFittingSize: layoutAttributes.size];
    CGRect cellFrame = layoutAttributes.frame;
    cellFrame.size.height= size.height;
    layoutAttributes.frame= cellFrame;
    return layoutAttributes;
}

@end
